﻿using System;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Represents an attribute of an HTML document.
    /// </summary>
    [Serializable]
    [Standalone]
    public class Meta : Element {
        private string _charset;
        private string _content;
        private string _httpequiv;
        private string _name;
        private string _scheme;

        /// <summary>
        /// Constructs a new instance of a Meta element.
        /// </summary>
        public Meta() { }

        /// <summary>
        /// Constructs a new instance of a Meta element with the given
        /// Content and HTTP-EQUIV fields.
        /// </summary>
        /// <param name="httpEquiv">The equivalent HTTP header that this Meta
        /// element corresponds to.</param>
        /// <param name="content">The content of this Meta element.</param>
        public Meta(string httpEquiv, string content) {
            _content = content;
            _httpequiv = httpEquiv;
        }

        /// <summary>
        /// Determines the character encoding of the page.
        /// </summary>
        public string Charset {
            get { return _charset; }
            set { _charset = value; }
        }

        /// <summary>
        /// Determines the data associated with the "http-equiv" or "name"
        /// fields.
        /// </summary>
        public string Content {
            get { return _content; }
            set { _content = value; }
        }

        /// <summary>
        /// Defines a tag that can alter the client's behavior.
        /// </summary>
        public string HttpEquiv {
            get { return _httpequiv; }
            set { _httpequiv = value; }
        }

        /// <summary>
        /// Determines the name of this attribute.
        /// </summary>
        public string Name {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// Determines the scheme in which the metadata is described.
        /// </summary>
        [Obsolete("Deprecated. No well-defined use for this.")]
        public string Scheme {
            get { return _scheme; }
            set { _scheme = value; }
        }

        /// <summary>
        /// Gets a formatted string of all child elements of this element.
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's child
        /// data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _charset, "charset");
            AttributeWriter.Write(sb, _content, "content");
            AttributeWriter.Write(sb, _httpequiv, "http-equiv");
            AttributeWriter.Write(sb, _name, "name");
            AttributeWriter.Write(sb, _scheme, "scheme");
        }
    }
}
